package com.dg.river.core.util;

import android.content.Context;

import com.dg.river.contant.Constant;

/**
 * Created by hy on 2018/11/13
 * Description : 缓存工具类
 */
public class ACacheUtils {

    public static ACacheUtils aCacheUtils;

    public static ACacheUtils getInstance() {
        if (aCacheUtils == null) {
            synchronized (ACacheUtils.class) {
                aCacheUtils = new ACacheUtils();
            }
        }
        return aCacheUtils;
    }

    /**
     * 根据key获取存储的内容
     *
     * @param mContext
     * @param key
     */
    public String getForKey(Context mContext, String key) {
        if (mContext != null) {
            ACache aCache = ACache.get(mContext);
            String str = aCache.getAsString(key);
            return TextUtil.isEmptyConvert(str);
        } else {
            return "";
        }
    }

    /**
     * 根据key存储内容
     *
     * @param mContext
     * @param key
     * @param value
     */
    public void putForKey(Context mContext, String key, String value) {
        if (mContext != null) {
            ACache aCache = ACache.get(mContext);
            aCache.put(key, value, Constant.CACHE_SAVE_TIME);
        }
    }
}
